package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfConfirmedUrl;
import com.yuandian.api.management.validate.InsertFlag;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.management.service.ConfConfirmedUrlService;
import com.yuandian.management.vo.ConfirmedResourceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Map;

/**
 * 已确认URL资源表-Controller
 * @author zfsn
 * @date 2023-3-17
 */
@Api(tags = "业务系统配置-IT云化资源配置-已确认")
@RestController
@RequestMapping("/confirmedUrl")
public class ConfConfirmedUrlController {

	@Autowired
	private ConfConfirmedUrlService confConfirmedUrlService;

	/**
	 * 查询数据
	 * @param confConfirmedUrl 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "查询数据", notes = "查询数据")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "segmentId", value = "所属网段", paramType = "body", required = false, dataType = "Integer"),
			@ApiImplicitParam(name = "confirmedUrl", value = "url", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isAsc", value = "排序的方向值只能是 desc 或者 asc", paramType = "body", required = true, dataType = "String")
	})
	public R<Page<Map<String, Object>>> getConfirmedList(@RequestBody @ApiIgnore ConfConfirmedUrl confConfirmedUrl){
		return R.ok(confConfirmedUrlService.getConfirmedList(confConfirmedUrl));
	}


	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@DeleteMapping("/delete/{id}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "query", required = true, dataType = "Integer"),
	})
	public R<String> removeByIds(@PathVariable("id") Integer id){
		return confConfirmedUrlService.deleteById(id);
	}



	/**
	 * 确认服务资源
	 * @param resourceCodes 业务服务资源编码数组
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "确认服务资源", notes = "确认服务资源")
	@PutMapping("/confirm/{resourceCodes}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCodes", value = "资源编码（可多选)", paramType = "query", required = true, dataType = "String"),
	})
	public R<String> confirmResource(@NotEmpty @PathVariable("resourceCodes") List<String> resourceCodes) {
		return confConfirmedUrlService.confirmOrCancelResourceByStatus(
				resourceCodes, true);
	}

	/**
	 * 取消确认服务资源
	 * @param resourceCodes 业务服务资源编码数组
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "取消确认服务资源", notes = "取消确认服务资源")
	@PutMapping("/cancel/{resourceCodes}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCodes", value = "资源编码（可多选)", paramType = "path", required = true, dataType = "String"),
	})
	public R<String> cancel(@PathVariable("resourceCodes") List<String> resourceCodes) {
		return confConfirmedUrlService.confirmOrCancelResourceByStatus(
				resourceCodes, false);
	}

	/**
	 * 再次确认服务资源
	 *
	 * @param crv 参数
	 * @return Result
	 */
	@ApiOperation(value = "再次确认服务资源", notes = "再次确认服务资源")
	@PostMapping("/confirmResourceAgain")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "confirmedUrl", value = "确认后的URL", paramType = "body", required = true,  dataType = "String"),
			@ApiImplicitParam(name = "systemId", value = "系统id", paramType = "body", required = true,  dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "segmentId", value = "网端id, 多个id 用, 连接", paramType = "body", required = true,  dataType = "String"),
	})
	public R confirmResourceAgain(@Validated({UpdateFlag.class}) @ApiIgnore @RequestBody ConfirmedResourceVo crv) {
		return confConfirmedUrlService.confirmResourceAgain(crv);
	}

}
